package 数组;

import java.util.Scanner;

public class 回形数 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        int n = scanner.nextInt();
        int[][] arr = new int[n][n];
        int num = 0;    //要显示的数据
        int maxX = n-1; //定义X轴最大值
        int maxY = n-1; //定义Y轴最大值
        int minX = 0;   //定义X轴最小值
        int minY = 0;   //定义Y轴最小值
        while(minX <= maxX){
            for (int x = minX; x <= maxX; x++) {
                arr[minY][x] = ++num;
            }
            minY++;
            for (int y = minY; y <= maxY; y++) {
                arr[y][maxX] = ++num;
            }
            maxX--;
            for (int x = maxX; x >= minX; x--) {
                arr[maxY][x] = ++num;
            }
            maxY--;
            for (int y = maxY; y >= minY; y--) {
                arr[y][minX] = ++num;
            }
            minX++;
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}
